package com.example.myapplication.tack_24.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.myapplication.R;
import com.example.myapplication.data.HomeServlet;
import com.example.myapplication.tack_04.Stop;
import com.example.myapplication.tack_06.Books;
import com.example.myapplication.tack_10.GovernmentActivity;
import com.example.myapplication.tack_13.OutpatientActivity;
import com.example.myapplication.tack_14.WasteActivity;
import com.example.myapplication.tack_17.SmartBusActivity;
import com.example.myapplication.tack_20.VolunteerActivity;
import com.example.myapplication.tack_22.MetroActivity;
import com.example.myapplication.tack_24.DetailActivity;
import com.example.myapplication.tack_24.data.FenLeiData;
import com.example.myapplication.utils.Common;
import com.example.myapplication.utils.OkHttpTool;

import java.util.List;

public class FenLeiAdapter extends RecyclerView.Adapter<FenLeiAdapter.My> {
    private List<FenLeiData.DataDTO> list;
    private Context context;
    private View view;

    public FenLeiAdapter(List<FenLeiData.DataDTO> list, Context context) {
        this.list = list;
        this.context = context;
    }

    @NonNull
    @Override
    public My onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        view = LayoutInflater.from(context).inflate(R.layout.servlet,null);
        return new My(view);
    }

    @Override
    public void onBindViewHolder(@NonNull My holder, int position) {
        Glide.with(context).load(OkHttpTool.URL + list.get(position).getImgUrl()).into(holder.imags);
        holder.name.setText(list.get(position).getName());
        holder.servlet.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, DetailActivity.class);
                intent.putExtra(Common.COMMON,String.valueOf(list.get(position).getId()));
                context.startActivity(intent);
            }
        });

    }


    @Override
    public int getItemCount() {
        return list != null?12:0;
    }

    public class My extends RecyclerView.ViewHolder{
        private ImageView imags;
        private TextView name;
        private RelativeLayout servlet;
        public My(@NonNull View itemView) {
            super(itemView);
            imags = view.findViewById(R.id.imags);
            name = view.findViewById(R.id.name);
            servlet = view.findViewById(R.id.servlet);
        }
    }
}
